﻿using System;
using System.Collections.Generic;
using Assist;
using Autodesk.Revit.DB;
using YJKRevitCode.ElmentSearchUtility.LinkDocumentSuite;
using SectionSignAndFilled.StairsRoomSection.DataDefine;
using SectionSignAndFilled.StairsRoomSection.Kit;

namespace SectionSignAndFilled.StairsRoomSection.ElementPacket
{
	internal class FloorObject : ComLayerObject
	{
		public FloorObject(BaseLinkDocumentResultBean LinkElem, SectionViewData secviewData = null) : base(LinkElem, secviewData)
		{
			this.m_objectType = ObjectType.kFloorType;
		}

		public override List<ElementObject> DividChild()
		{
			base.DividChild();
			foreach (ElementObject elementObject in base.LstChildObj)
			{
				elementObject.m_objectType = ObjectType.kFloorLayerType;
				(elementObject as LayerObject).m_MaxLayerIndex = base.MaxLayerIndex;
				(elementObject as LayerObject).m_MinLayerIndex = base.MinLayerIndex;
				(elementObject as LayerObject).m_parentObj = this;
			}
			return base.LstChildObj;
		}

		public override Plane GetLastLayerCutPlane(int index, Line cutLine)
		{
			Element useElement = base.SelfElem.UseElement;
			double num = 0.0;
			bool flag = false;
			foreach (ElementObject elementObject in base.LstChildObj)
			{
				LayerObject layerObject = elementObject as LayerObject;
				if (layerObject.m_IndexPos == index)
				{
					num += layerObject.m_dWidth;
					flag = true;
					break;
				}
				num += layerObject.m_dWidth;
			}
			if (!flag)
			{
				return null;
			}
			ElementId elementId = base.SelfElem.UseElement.get_Parameter(BuiltInParameter.LEVEL_PARAM).AsElementId();
			Level level = base.SelfElem.UseElement.Document.GetElement(elementId) as Level;
			double elevation = level.Elevation;
			XYZ xyz = new XYZ(0.0, 0.0, elevation);
			xyz -= num * new XYZ(0.0, 0.0, 1.0);
			return RevitVersionFuncs.CreatePlanByNormalAndOrigin(new XYZ(0.0, 0.0, 1.0), xyz);
		}
	}
}
